package com.ruoyi.project.system.task.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.task.domain.Task;
import com.ruoyi.project.system.task.service.TaskService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/system/task/accept")
public class AcceptController extends BaseController {

    private String prefix = "system/task/accept";

    @Autowired
    private TaskService taskService;

    /**
     * 跳转到接受任务
     * @return
     */
    @RequiresPermissions("system:accept:view")
    @GetMapping()
    public String accept()
    {
        return prefix + "/accept";
    }

    /**
     * 根据任务id查找接受的任务
     * @param taskId 任务id
     * @param mmap 回显的数据
     * @return
     */
    @GetMapping("/edit/{taskId}")
    public String edit(@PathVariable("taskId") Long taskId, ModelMap mmap)
    {
        mmap.put("task", taskService.selectTaskById(taskId));
        return prefix + "/edit";
    }

    /**
     * 修改任务id接受任务的状态
     * @param task 任务信息
     * @return
     */
    @RequiresPermissions("system:accept:edit")
    @Log(title = "任务接受查看", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Task task)
    {
        System.out.println(task.toString());
        return toAjax(taskService.updateTask(task));
    }


    /**
     * 更具条件分页查询
     * @param task 条件
     * @return
     */
    @RequiresPermissions("system:accept:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Task task)
    {
        startPage();
        List<Task> list = taskService.selectAcceptList(task);
        return getDataTable(list);
    }

}
